package com.scanner;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Point;
import android.view.Display;
import android.view.WindowManager;

@SuppressLint("NewApi")
public class CenterButton {
	
	private int buttonX;
	private int buttonY;
	private int radius = 60;
	private int senseThreshold;
	
	private boolean stateEnabled;

	public int getSenseThreshold() {
		return senseThreshold;
	}

	public void setSenseThreshold(int senseThreshold) {
		this.senseThreshold = senseThreshold;
	}

	public int getButtonX() {
		return buttonX;
	}

	public void setButtonX(int buttonX) {
		this.buttonX = buttonX;
	}	

	public int getButtonY() {
		return buttonY;
	}

	public void setButtonY(int buttonY) {
		this.buttonY = buttonY;
	}

	public int getRadius() {
		return radius;
	}

	public void setRadius(int radius) {
		this.radius = radius;
	}
	
	public boolean isStateEnabled() {
		return stateEnabled;
	}

	public void setStateEnabled(boolean stateEnabled) {
		this.stateEnabled = stateEnabled;		
	}
	
	public CenterButton(Context context)
	{
		WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		Display display = wm.getDefaultDisplay();
		Point size = new Point();
		display.getSize(size);
		
		buttonX = size.x/2;
		buttonY = size.y/2;
		stateEnabled = false;
		
		senseThreshold = 0;
	}
	

	public boolean IsHit(int x, int y)
	{
		int effectiveRadius = radius + senseThreshold;
		int xDist = Math.abs(x-buttonX);
		int yDist = Math.abs(y-buttonY);
		if (( xDist <= effectiveRadius) && (yDist <= effectiveRadius))
		{
			return true;
		}
		return false;
	}
	
	//for testing
	public boolean IsTopRightHit(int x, int y)
	{
		if (x<100 && y<100)
		{
			return true;
		}
		
		return false;
	}
	//for testing
	public boolean IsDownLeftHit(int x, int y)
	{
		if (x>1000 && y>500)
		{
			return true;
		}
		
		return false;
	}

}
